package com.doge.service.wx.brand;

import com.doge.bean.base.BaseData;
import com.doge.bean.pojo.brand.Brand;
import com.doge.bean.pojo.brand.BrandExample;
import com.doge.mapper.BrandMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: doge
 * @description: 微信品牌服务
 * @author: Mr.Jiang
 * @create: 2021-12-02 10:53
 **/
@Service
public class WxBrandServiceImpl implements WxBrandService {
    @Autowired
    BrandMapper brandMapper;
    @Override
    public BaseData list(Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        BrandExample brandExample = new BrandExample();
        brandExample.createCriteria().andDeletedEqualTo(false);
        brandExample.setOrderByClause("add_time desc");
        List<Brand> brands = brandMapper.selectByExample(brandExample);
        PageInfo pageInfo = new PageInfo(brands);
        BaseData baseData = new BaseData();
        baseData.setTotal(pageInfo.getTotal());
        baseData.setPages(pageInfo.getPages());
        baseData.setLimit(limit);
        baseData.setPage(page);
        baseData.setList(brands);
        return baseData;
    }

    @Override
    public Brand detail(Integer id) {
        Brand brand = brandMapper.selectByPrimaryKey(id);
        return brand;
    }
}
